<?php

class MD_Services extends ModelBase {

    function MD_Services(&$database) {
	$this->tableName = TABLE_SERVICES;
	$this->keyField = "id";
	ModelBase::ModelBase($database);
    }
    function getById($id) {
	$sql = "SELECT *  FROM $this->tableName ";
	if ($id != "") {
	    $sql .= " WHERE $this->keyField =$id ";
	}
	return $this->db->retrieve($sql);
    }

    function get_services_type_by_Where($where, $order, $limit) {
	$sql = "SELECT *  FROM tbl_services_type";
	if ($where != "") {
	    $sql .= " WHERE $where ";
	}
	if ($order != "") {
	    $sql .= " ORDER BY $order ";
	}
	if ($limit != "") {
	    $sql .= " LIMIT $limit ";
	}
//	echo $sql."<br/>";
	return $this->db->retrieve($sql);
    }

    function get_services_type_by_Where_1($where, $order, $limit) {
	$sql = "SELECT *  FROM tbl_services_type";
	if ($where != "") {
	    $sql .= " WHERE $where ";
	}
	if ($order != "") {
	    $sql .= " ORDER BY $order ";
	}
	if ($limit != "") {
	    $sql .= " LIMIT $limit ";
	}
//	echo $sql."<br/>";
	return $this->db->getFirstRecord($sql);
    }

    function insert_type(&$arrayData) {
	$listFilds .= "service_type_name";
	$listValues .= "'" . $this->replaceString(&$arrayData["service_type_name"]) . "'";
	$listFilds .= ",service_type_note";
	$listValues .= ",'" . $this->replaceString(&$arrayData["service_type_note"]) . "'";
	$listFilds .= ",parent_id";
	$listValues .= ",'" . $this->replaceString(&$arrayData["parent_id"]) . "'";

	$sql = "INSERT INTO tbl_services_type (  $listFilds ) ";
	$sql .= " VALUES ($listValues ); ";
//	echo $sql;
//	die();
	$this->db->query($sql);
    }    
    
    function delete_type($id) {
	$sql = "DELETE FROM tbl_services_type WHERE $this->keyField =$id";
//	echo $sql;
	return $this->db->query($sql);
    }
    
     function update_type(&$arrayData) {
	$sql = "UPDATE  tbl_services_type SET ";
	$sql .= "service_type_name='" . $this->replaceString(&$arrayData["service_type_name"]) . "'";
	$sql .= ",service_type_note='" . $this->replaceString(&$arrayData["service_type_note"]) . "'";
	$sql .= ",parent_id='" . $this->replaceString(&$arrayData["parent_id"]) . "'";

	$sql .= " WHERE $this->keyField=" . $arrayData["type_id"];
//	echo $sql;
//	die();
	$this->db->query($sql);
    }
    
    function delete_services($id) {
	$sql = "DELETE FROM $this->tableName WHERE $this->keyField =$id";
//	echo $sql;
	return $this->db->query($sql);
    }
    
    function update_services(&$arrayData) {
	$sql = "UPDATE  " . $this->tableName . " SET ";
	$sql .= "services_name='" . $this->replaceString(&$arrayData["services_name"]) . "'";
	$sql .= ",services_info='" . $this->replaceString(&$arrayData["services_info"]) . "'";
	$sql .= ",services_type='" . $this->replaceString(&$arrayData["services_type"]) . "'";
	
	$sql .= " WHERE $this->keyField=" . $arrayData["id"];
	$this->db->query($sql);
    }

    function insert_services(&$arrayData) {
	$listFilds .= "services_name";
	$listValues .= "'" . $this->replaceString(&$arrayData["services_name"]) . "'";
	$listFilds .= ",services_info";
	$listValues .= ",'" . $this->replaceString(&$arrayData["services_info"]) . "'";
	$listFilds .= ",services_type";
	$listValues .= ",'" . $this->replaceString(&$arrayData["services_type"]) . "'";
	
	$sql = "INSERT INTO $this->tableName (  $listFilds ) ";
	$sql .= " VALUES ($listValues ); ";
//	echo $sql;
//	die();
	$this->db->query($sql);
    }

}

?>